//
//  ECData_Format.m
//  EduCourse
//
//  Created by yanyan on 2017/8/9.
//  Copyright © 2017年 yanyan. All rights reserved.
//

#import "ECData_Format.h"
#import "CategoryModel.h"
@implementation ECData_Format
+(NSArray *)arrayForHomeMenuWithData:(id)obj
{
    //[obj valueForKey:@"rootcategories"]
    NSMutableArray *categorys = [NSMutableArray array];
    NSArray *images = @[@"chomeTag_primary",@"chomeTag_junior",@"chomeTag_high",@"chomeTag_university"];
//    for (int i = 0; i < [((NSArray *)obj) count]; i ++) {
//        id category = obj[i];
//        [categorys addObject:@{@"id":[category valueForKey:@"id"],@"name":[category valueForKey:@"name"],@"brief":[images objectAtIndex:(i%4)]}];
//
//    }
//    [categorys addObject:@{@"id":@"",@"name":@"更多",@"brief":@"chomeTag_more"}];

    for (int i = 0; i < [((NSArray *)obj) count]; i ++) {
         id category = obj[i];
        PrimaryCategoryModel *mo = [[PrimaryCategoryModel alloc]initWithObject:category];
        [categorys addObject:@{@"object":mo,@"brief":[images objectAtIndex:(i%4)]}];

    }
    PrimaryCategoryModel *mo_more = [[PrimaryCategoryModel alloc]init];
    mo_more.title = @"更多";
[categorys addObject:@{@"object":mo_more,@"brief":@"chomeTag_more"}];
    return  categorys;
}
+(NSArray*)arrayForHomeAllCategorysWithData:(id) obj{
    NSMutableArray *arr = [NSMutableArray array];
    for (id mo_obj in obj) {
        PrimaryCategoryModel *mo = [[PrimaryCategoryModel alloc]initWithObject:mo_obj hasAll:NO];
        [arr addObject:mo];
    }
    return arr;
}

+ (NSArray *)arrayForCategoryWithAll:(id)obj
{
    NSMutableArray *categoryData = [NSMutableArray array];
    if (((NSArray *) obj).count > 0) {
        PrimaryCategoryModel *mo = [[PrimaryCategoryModel alloc]init];
        mo.title = @"全部";
        mo.modelId = @"";
        mo.subCategoryArray = [NSMutableArray array];
        [categoryData addObject:mo];
    }
    for (id mo_obj in obj) {
        PrimaryCategoryModel *mo = [[PrimaryCategoryModel alloc]initWithObject:mo_obj];
        [categoryData addObject:mo];
    }
    return categoryData;
}
+ (NSString *)orderStateStringForState:(ECCourseOrderModel *)mo
{
    if ([mo.orderState isEqualToString:@"cancelled"]) {
        return @"已取消";
    }
    if ([mo.orderState isEqualToString:@"created"]) {
        return @"待支付";
    }
    if ([mo.orderState isEqualToString:@"paid"]) {
        if (mo.reviewed) {
            return @"已完成";
        }
        return @"待评价";
    }
    return @"已关闭";
}
+ (UIColor *)orderStateColorForState:(ECCourseOrderModel *)mo
{
    if ([mo.orderState isEqualToString:@"cancelled"]) {
        return [UIColor colorWithHex:0xbfbfbf];
    }
    if ([mo.orderState isEqualToString:@"created"]) {
        return [UIColor colorWithHex:0xff6700];
    }
    if ([mo.orderState isEqualToString:@"paid"]) {
        if (mo.reviewed) {
            //已经评价的，完成
            return [UIColor colorWithHex:0x279af7];
        }
        return [UIColor colorWithHex:0x279af7];
    }
    return [UIColor colorWithHex:0xbfbfbf];
}
+ (NSDictionary*)dictForOrderPaidTime:(ECCourseOrderModel *)mo
{
    if ([mo.orderState isEqualToString:@"paid"]) {
        return @{@"name":@"付款时间",@"brief":mo.paidTime};;

    }
    return  nil;

}
+ (NSDictionary*)dictForCoursePriceOfOrder:(ECCourseOrderModel *)mo
{
    UIColor *color = [UIColor colorWithHex:0x666666];
    if ([mo.orderState isEqualToString:@"cancelled"]) {
        return @{@"name":@"课程价格",@"brief":[NSString stringWithFormat:@"¥ %@",mo.mo_course.price],@"color":color};
    }
    
    if ([mo.orderState isEqualToString:@"created"]) {
        color = [UIColor colorWithHex:0xef4023];
        return @{@"name":@"课程价格",@"brief":[NSString stringWithFormat:@"¥ %@",mo.mo_course.price],@"color":color};
    }
    return @{@"name":@"课程价格",@"brief":[NSString stringWithFormat:@"¥ %@",mo.mo_course.price],@"color":color};
    
}
// 应付金额 & 实付金额
+ (NSDictionary*)dictForOrderPaidMoney:(ECCourseOrderModel *)mo
{
    UIColor *color = [UIColor colorWithHex:0x666666];
    if ([mo.orderState isEqualToString:@"cancelled"]) {
        return @{@"name":@"应付金额",@"brief":[NSString stringWithFormat:@"¥ %@",mo.totalPrice],@"color":color};
    }
    if ([mo.orderState isEqualToString:@"created"]) {
        color = [UIColor colorWithHex:0xef4023];
        return @{@"name":@"应付金额",@"brief":[NSString stringWithFormat:@"¥ %@",mo.totalPrice],@"color":color};
    }
return @{@"name":@"实付金额",@"brief":[NSString stringWithFormat:@"¥ %@",mo.totalPrice],@"color":color};
    
}
// 支付方式
+ (NSDictionary*)dictForOrderPaidStyle:(ECCourseOrderModel *)mo
{
    UIColor *color = [UIColor colorWithHex:0x666666];

    if ([mo.orderState isEqualToString:@"paid"]) {
        return @{@"name":@"支付方式",@"brief":mo.payment,@"color":color};
    }
    return nil;
}
+(NSArray *)arrayForOrderDetail:(id)obj{
    ECCourseOrderModel *mo = obj;
    NSMutableArray *dataSource = [NSMutableArray array];
    NSMutableArray *arr = [NSMutableArray array];
    NSDictionary *dict0 = @{@"name":@"订单状态",@"brief":[ECData_Format orderStateStringForState:mo],@"color":[ECData_Format orderStateColorForState:mo]};
    NSDictionary *dict1 = @{@"name":@"订单编号",@"brief":mo.orderSN};
    NSDictionary *dict2 = @{@"name":@"下单时间",@"brief":mo.createdTime};
    NSDictionary *dict3 = [ECData_Format dictForOrderPaidTime:mo];

    if (dict3) {
        [dataSource addObject:@[dict0,dict1,dict2,dict3]];
    } else {
        [dataSource addObject:@[dict0,dict1,dict2]];
    }
    // 第二分区
    NSDictionary *dict21 = [ECData_Format dictForCoursePriceOfOrder:mo];
    NSDictionary *dict22 = [ECData_Format dictForOrderPaidMoney:mo];
    NSDictionary *dict23 = [ECData_Format dictForOrderPaidStyle:mo];

    
    if (dict3) {
        if ([mo.totalPrice floatValue] > 0) {
            [dataSource addObject:@[mo,dict21,dict22,dict23]];
            
        }else{
            [dataSource addObject:@[mo,dict21,dict22]];

        }
    } else {
        [dataSource addObject:@[mo,dict21,dict22]];

    }
    return dataSource;
}
+(NSArray *)arrayForOrderPayCenter:(id)obj
{
    CourseModel *mo = obj;
    ;
    NSDictionary *dict0 = @{@"name":@"课程原价",@"brief":[NSString stringWithFormat:@"¥ %@",mo.price],@"color":[UIColor colorWithHex:0xef4023]};
    NSDictionary *dict1 = @{@"name":@"合计",@"brief":[NSString stringWithFormat:@"¥ %@",mo.price],@"color":[UIColor colorWithHex:0xef4023]};

    return @[dict0,dict1];
}
+ (NSArray *)arrayForOrderCashStyle:(id)obj
{
    NSDictionary *dict0 = @{@"name":@"支付宝",@"brief":@"支付宝支付，更快捷，更方便",@"image":@"orderPay_ali"};
    NSDictionary *dict1 = @{@"name":@"微信支付",@"brief":@"亿万用户的选择，更快更安全",@"image":@"orderPay_weixin"};
    
    return @[dict0,dict1];
}
@end
